<template>
  <router-view />
</template>

<script setup>
import { onMounted, onUnmounted } from 'vue'
import { useAppStore } from '@/store/modules/app'

const appStore = useAppStore()

// 定时器 ID
let resizeTimeout = null

// 窗口大小变化处理函数
function windowSize() {
  if (resizeTimeout) return

  resizeTimeout = setTimeout(() => {
    appStore.setWindowHeight(window.innerHeight)
    appStore.setWindowWidth(window.innerWidth)
    resizeTimeout = null
  }, 500)
}

// 挂到全局
window.vue = { appStore }

onMounted(() => {
  window.addEventListener('resize', windowSize)
  windowSize() // 初始化时调用一次
})

onUnmounted(() => {
  window.removeEventListener('resize', windowSize)
})
</script>
<style lang="scss">
@import "@/assets/css/base.scss";
</style>
